<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>美食分类 - 美食社区</title>
    <!-- Bootstrap CSS -->
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.1/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.4.2/css/all.min.css" rel="stylesheet">
    <link rel="stylesheet" th:href="@{/css/style.css}">
    <style>
        .category-card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
            height: 100%;
            border-radius: 10px;
            overflow: hidden;
        }

        .category-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        }

        .category-img {
            height: 200px;
            overflow: hidden;
            position: relative;
        }

        .category-img img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            transition: transform 0.3s ease;
        }

        .category-card:hover .category-img img {
            transform: scale(1.1);
        }

        .category-overlay {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: linear-gradient(to bottom, rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.7));
            display: flex;
            align-items: flex-end;
            padding: 20px;
        }

        .category-name {
            color: white;
            font-size: 24px;
            font-weight: 700;
            margin: 0;
        }

        .category-count {
            color: rgba(255, 255, 255, 0.8);
            font-size: 14px;
        }

        .btn-primary {
            background-color: #fd7e14;
            border-color: #fd7e14;
        }

        .btn-primary:hover {
            background-color: #e76b00;
            border-color: #e76b00;
        }
    </style>
</head>

<body>
    <!-- 导航栏 -->
    <nav th:replace="~{common/header :: header}"></nav>

    <div class="container mt-5 pt-5">
        <h2 class="section-title mb-4">美食分类</h2>

        <!-- 分类列表 -->
        <div class="row g-4">
            <!-- 动态生成分类卡片 -->
            <div class="col-md-4 mb-4" th:each="category : ${categories}">
                <div class="category-card">
                    <div class="category-img">
                        <img th:src="${category.imageUrl != null ? category.imageUrl : 'https://images.unsplash.com/photo-1563245372-f21724e3856d'}"
                            th:alt="${category.name}">
                        <div class="category-overlay">
                            <div>
                                <h3 class="category-name" th:text="${category.name}">分类名称</h3>
                                <p class="category-count"
                                    th:text="${category.postCount != null ? category.postCount + ' 篇文章' : '0 篇文章'}">文章数量
                                </p>
                            </div>
                        </div>
                    </div>
                    <div class="card-body">
                        <p class="card-text" th:text="${category.description}">分类描述</p>
                        <a th:href="@{/posts(category=${category.name})}" class="btn btn-primary w-100">浏览文章</a>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Bootstrap Bundle with Popper -->
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.1/js/bootstrap.bundle.min.js"></script>
    <!-- jQuery -->
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <!-- 退出登录脚本 -->
    <script th:replace="~{common/header :: logout-script}"></script>
</body>

</html>